<?php

include_once __DIR__ . '/../vendor/autoload.php';
include_once __DIR__ . '/../db.php';

$type = @$_POST['type'] ?: '';
$date = @$_POST['date'] ?: '';
$config = $configs[$type];
$r = r($config[0], $config[1]);
$circles = numbers(@$_POST['circles'] ?: '') ?: implode(',', array_map($r, array_fill(0, $config[2], '')));
$specials = numbers(@$_POST['specials'] ?: '') ?: ($config[3] ? $r() : '');
$money = @$_POST['money'] ?: mt_rand($config[4], $config[5]);

if (!isDrawDay($type, $date)) {
    echo "<script>alert('{$date} 当前没有开奖！');window.location=document.referrer;</script>";
    exit;
}

\Data::updateOrCreate(compact('type', 'date'), compact('circles', 'specials', 'money'));

echo "<script>alert('操作成功');window.location=document.referrer;</script>";
